package com.simple.auth.service.impl;


import com.simple.auth.service.SmsService;
import com.simple.common.constant.CommonConstants;
import com.simple.common.exception.ServiceException;
import com.simple.common.sms.SmsMessageService;
import com.simple.framework.core.redis.RedisService;
import org.springframework.stereotype.Service;

/**
 * @Description 阿里云短信服务
 * @Author xiaoke
 * @Date 2024/8/10 18:00
 * @Version 1.0
 */
@Service("alySmsServiceService")
public class AlySmsServiceServiceImpl implements SmsService {

    private final SmsMessageService messageService;

    private final RedisService redisService;

    public AlySmsServiceServiceImpl(SmsMessageService messageService, RedisService redisService) {
        this.messageService = messageService;
        this.redisService = redisService;
    }

    @Override
    public boolean sendVerificationCode(String phone) {
        String key = CommonConstants.SMS_VALUE+phone;
        if (redisService.hasKey(key)) {
            throw new ServiceException("验证码发送频繁，请稍后再试");
        }
        return messageService.sendVerificationCode(phone, null);
    }
}
